﻿//	Copyright (c) 2012 Jonathan Loe
//
//	MIT license (http://en.wikipedia.org/wiki/MIT_License)
//
//	Permission is hereby granted, free of charge, to any person obtaining a copy
//	of this software and associated documentation files (the "Software"), to deal
//	in the Software without restriction, including without limitation the rights 
//	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
//	of the Software, and to permit persons to whom the Software is furnished to do so, 
//	subject to the following conditions:
//
//	The above copyright notice and this permission notice shall be included in all 
//	copies or substantial portions of the Software.
//
//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
//	INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
//	PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
//	FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
//	ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Ordinaire.Business.FoodBeverage.Sales;

namespace Ordinaire.Business.FoodBeverage.Security
{
    /// <summary>
    /// Represents the administrator for the F&B system.
    /// </summary>
    public class Administrator: User, Ordinaire.Security.IAdministrator
    {
        /// <summary>
        /// Ordinaire.Security.Administrator instance.
        /// </summary>
        private Ordinaire.Security.IAdministrator administrator;

        /// <summary>
        /// Returns new instance of Ordinaire.Business.FoodBeverage.Security.Administrator
        /// </summary>
        /// <param name="administrator"></param>
        internal Administrator(Ordinaire.Security.IAdministrator administrator)
        {
            Ordinaire.Security.Administrator user = (Ordinaire.Security.Administrator)administrator;

            username       = user.Username;
            displayName    = user.DisplayName;
            authentication = user.Authentication;
            authorisation  = user.Authorisation;
            roles          = user.Roles;

            this.administrator = administrator;
        }

        /// <summary>
        /// Assigns the username with the specified role name.
        /// </summary>
        /// <param name="username">username</param>
        /// <param name="name">role name</param>
        /// <returns>true if successful, else false</returns>
        public bool AssignRole(string username, string name)
        {
            return administrator.AssignRole(username, name);
        }

        /// <summary>
        /// Creates new user with the specified username and password
        /// </summary>
        /// <param name="username">the user's id</param>
        /// <param name="password">the user's password</param>
        /// <returns>true if user details was created, else false</returns>
        public bool CreateUser(string username, string password)
        {
            return administrator.CreateUser(username, password);
        }

        /// <summary>
        /// Creates new role with the specified name. New role created  will be under admin role.
        /// </summary>
        /// <param name="name">the new role name</param>
        /// <returns>new instance of Ordinaire.Security.Role</returns>
        public Ordinaire.Security.Role CreateRole(string name)
        {
            return administrator.CreateRole(name);
        }

        public bool AddBeverage(
            string  name,
            int     quantity,
            string  unit,
            decimal price,
            decimal discount,
            decimal tax
        )
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            Beverage beverage = new Beverage();
            beverage.Name     = name;
            beverage.Quantity = quantity;
            beverage.Unit     = unit;
            beverage.Price    = price;
            beverage.Discount = discount;
            beverage.Tax      = tax;

            //Menu menu = new Menu();
            //return menu.Add(beverage, this);
            return false;
        }

        public bool AddFood(
            string  name,
            string  description,
            int     quantity,
            string  unit,
            decimal price,
            decimal discount,
            decimal tax
        )
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            Food food        = new Food();
            food.Name        = name;
            food.Description = description;
            food.Quantity    = quantity;
            food.Unit        = unit;
            food.Price       = price;
            food.Discount    = discount;
            food.Tax         = tax;

            //Menu menu = new Menu();
            //return menu.Add(food, this);
            return false;
        }
    }
}
